Some fixes and tidy ups