Fix #547, fix #543

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