Minor bugfix and tidying up