Fix #656

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

Signed-off-by: Ross Allan <rallanpcl@gmail.com>
Fix another issue in #660.

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