Fix #1172, fix #1168, fix #1162

Signed-off-by: Ross Allan <rallanpcl@gmail.com>