Few bug fixes and tidying