Code fixes and tidy