Bugfixes and enhancements

Signed-off-by: Luke Oatham <lukeoatham@gmail.com>