diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp
index 1561cf6cb3..229ef5c727 100644
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -230,8 +230,8 @@ static int CDECL TrainEngineRunningCostSorter(const void *a, const void *b)
 	const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a);
 	const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b);
 
-	Money va = rvi_a->running_cost * GetPriceByIndex(rvi_a->running_cost_class) * (rvi_a->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
-	Money vb = rvi_b->running_cost * GetPriceByIndex(rvi_b->running_cost_class) * (rvi_b->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
+	Money va = rvi_a->running_cost * GetPriceByIndex(rvi_a->running_cost_class);
+	Money vb = rvi_b->running_cost * GetPriceByIndex(rvi_b->running_cost_class);
 	int r = ClampToI32(va - vb);
 
 	return _internal_sort_order ? -r : r;
@@ -266,8 +266,11 @@ static int CDECL TrainEngineNumberSorter(const void *a, const void *b)
 
 static int CDECL TrainEngineCapacitySorter(const void *a, const void *b)
 {
-	int va = RailVehInfo(*(const EngineID*)a)->capacity;
-	int vb = RailVehInfo(*(const EngineID*)b)->capacity;
+	const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a);
+	const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b);
+
+	int va = rvi_a->capacity * (rvi_a->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
+	int vb = rvi_b->capacity * (rvi_b->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
 	int r = va - vb;
 
 	if (r == 0) {
diff --git a/src/cargopacket.cpp b/src/cargopacket.cpp
index e97ff866c9..b19da9a5b0 100644
--- a/src/cargopacket.cpp
+++ b/src/cargopacket.cpp
@@ -217,19 +217,21 @@ bool CargoList::MoveTo(CargoList *dest, uint count, CargoList::MoveToAction mta,
 			/* Can move only part of the packet, so split it into two pieces */
 			if (mta != MTA_FINAL_DELIVERY) {
 				CargoPacket *cp_new = new CargoPacket();
+
+				Money fs = cp->feeder_share * count / cp->count;
+				cp->feeder_share -= fs;
+
 				cp_new->source          = cp->source;
 				cp_new->source_xy       = cp->source_xy;
 				cp_new->loaded_at_xy    = (mta == MTA_CARGO_LOAD) ? data : cp->loaded_at_xy;
 
 				cp_new->days_in_transit = cp->days_in_transit;
-				cp_new->feeder_share    = cp->feeder_share / count;
+				cp_new->feeder_share    = fs;
 				/* When cargo is moved into another vehicle you have *always* paid for it */
 				cp_new->paid_for        = (mta == MTA_CARGO_LOAD) ? false : cp->paid_for;
 
 				cp_new->count = count;
 				dest->packets.push_back(cp_new);
-
-				cp->feeder_share /= cp->count - count;
 			}
 			cp->count -= count;
 
diff --git a/src/gfx_type.h b/src/gfx_type.h
index aa0748f597..b7cd08b787 100644
--- a/src/gfx_type.h
+++ b/src/gfx_type.h
@@ -72,16 +72,6 @@ enum WindowKeyCodes {
 	 * a-z are mapped to 97-122 */
 
 	/* Numerical keyboard */
-	WKC_NUM_0       = 128,
-	WKC_NUM_1       = 129,
-	WKC_NUM_2       = 130,
-	WKC_NUM_3       = 131,
-	WKC_NUM_4       = 132,
-	WKC_NUM_5       = 133,
-	WKC_NUM_6       = 134,
-	WKC_NUM_7       = 135,
-	WKC_NUM_8       = 136,
-	WKC_NUM_9       = 137,
 	WKC_NUM_DIV     = 138,
 	WKC_NUM_MUL     = 139,
 	WKC_NUM_MINUS   = 140,
diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp
index 45c31a1c61..310ee3e83a 100644
--- a/src/graph_gui.cpp
+++ b/src/graph_gui.cpp
@@ -765,7 +765,7 @@ static void CargoPaymentRatesWndProc(Window *w, WindowEvent *e)
 
 				gd.colors[i] = cs->legend_colour;
 				for (uint j = 0; j != 20; j++) {
-					gd.cost[i][j] = GetTransportedGoodsIncome(10, 20, j * 6 + 6, c);
+					gd.cost[i][j] = GetTransportedGoodsIncome(10, 20, j * 4 + 4, c);
 				}
 
 				i++;
diff --git a/src/openttd.h b/src/openttd.h
index 1050d16799..cb6fc093bb 100644
--- a/src/openttd.h
+++ b/src/openttd.h
@@ -115,7 +115,7 @@ enum {
 struct ViewportSign {
 	int32 left;
 	int32 top;
-	byte width_1, width_2;
+	uint16 width_1, width_2;
 };
 
 enum {
diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp
index 07baf6b2f3..deed4acd1c 100644
--- a/src/smallmap_gui.cpp
+++ b/src/smallmap_gui.cpp
@@ -877,6 +877,7 @@ static void SmallMapWindowProc(Window *w, WindowEvent *e)
 					_left_button_clicked = false;
 
 					pt = RemapCoords(WP(w, smallmap_d).scroll_x, WP(w,smallmap_d).scroll_y, 0);
+					WP(w2, vp_d).follow_vehicle = INVALID_VEHICLE;
 					WP(w2, vp_d).dest_scrollpos_x = pt.x + ((_cursor.pos.x - w->left + 2) << 4) - (w2->viewport->virtual_width >> 1);
 					WP(w2, vp_d).dest_scrollpos_y = pt.y + ((_cursor.pos.y - w->top - 16) << 4) - (w2->viewport->virtual_height >> 1);
 
diff --git a/src/string_func.h b/src/string_func.h
index 0733931f30..570218ff63 100644
--- a/src/string_func.h
+++ b/src/string_func.h
@@ -48,7 +48,7 @@ static inline bool StrEmpty(const char *s) { return s == NULL || s[0] == '\0'; }
 static inline int ttd_strnlen(const char *str, int maxlen)
 {
 	const char *t;
-	for (t = str; *t != '\0' && t - str < maxlen; t++) {}
+	for (t = str; t - str < maxlen && *t != '\0'; t++) {}
 	return t - str;
 }
 
diff --git a/src/video/cocoa/event.mm b/src/video/cocoa/event.mm
index 3e8fc68c17..dd561153b4 100644
--- a/src/video/cocoa/event.mm
+++ b/src/video/cocoa/event.mm
@@ -242,16 +242,16 @@ static const VkMapping _vk_mapping[] = {
 	AS(QZ_F12, WKC_F12),
 
 	/* Numeric part */
-	AS(QZ_KP0,         WKC_NUM_0),
-	AS(QZ_KP1,         WKC_NUM_1),
-	AS(QZ_KP2,         WKC_NUM_2),
-	AS(QZ_KP3,         WKC_NUM_3),
-	AS(QZ_KP4,         WKC_NUM_4),
-	AS(QZ_KP5,         WKC_NUM_5),
-	AS(QZ_KP6,         WKC_NUM_6),
-	AS(QZ_KP7,         WKC_NUM_7),
-	AS(QZ_KP8,         WKC_NUM_8),
-	AS(QZ_KP9,         WKC_NUM_9),
+	AS(QZ_KP0,         '0'),
+	AS(QZ_KP1,         '1'),
+	AS(QZ_KP2,         '2'),
+	AS(QZ_KP3,         '3'),
+	AS(QZ_KP4,         '4'),
+	AS(QZ_KP5,         '5'),
+	AS(QZ_KP6,         '6'),
+	AS(QZ_KP7,         '7'),
+	AS(QZ_KP8,         '8'),
+	AS(QZ_KP9,         '9'),
 	AS(QZ_KP_DIVIDE,   WKC_NUM_DIV),
 	AS(QZ_KP_MULTIPLY, WKC_NUM_MUL),
 	AS(QZ_KP_MINUS,    WKC_NUM_MINUS),
diff --git a/src/video/sdl_v.cpp b/src/video/sdl_v.cpp
index 12478cfc9d..8ca263a589 100644
--- a/src/video/sdl_v.cpp
+++ b/src/video/sdl_v.cpp
@@ -268,7 +268,7 @@ static const VkMapping _vk_mapping[] = {
 	AM(SDLK_F1, SDLK_F12, WKC_F1, WKC_F12),
 
 	/* Numeric part. */
-	AM(SDLK_KP0, SDLK_KP9, WKC_NUM_0, WKC_NUM_9),
+	AM(SDLK_KP0, SDLK_KP9, '0', '9'),
 	AS(SDLK_KP_DIVIDE,   WKC_NUM_DIV),
 	AS(SDLK_KP_MULTIPLY, WKC_NUM_MUL),
 	AS(SDLK_KP_MINUS,    WKC_NUM_MINUS),
diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp
index 91f7439fa9..3b7a6d564c 100644
--- a/src/video/win32_v.cpp
+++ b/src/video/win32_v.cpp
@@ -101,7 +101,7 @@ static const VkMapping _vk_mapping[] = {
 	AM(VK_F1, VK_F12, WKC_F1, WKC_F12),
 
 	/* Numeric part */
-	AM(VK_NUMPAD0, VK_NUMPAD9, WKC_NUM_0, WKC_NUM_9),
+	AM(VK_NUMPAD0, VK_NUMPAD9, '0', '9'),
 	AS(VK_DIVIDE,   WKC_NUM_DIV),
 	AS(VK_MULTIPLY, WKC_NUM_MUL),
 	AS(VK_SUBTRACT, WKC_NUM_MINUS),
diff --git a/src/viewport.cpp b/src/viewport.cpp
index b9cfa92cf1..a42210a5df 100644
--- a/src/viewport.cpp
+++ b/src/viewport.cpp
@@ -1348,7 +1348,7 @@ static void ViewportAddWaypoints(DrawPixelInfo *dpi)
 
 void UpdateViewportSignPos(ViewportSign *sign, int left, int top, StringID str)
 {
-	char buffer[128];
+	char buffer[256];
 	uint w;
 
 	sign->top = top;