some code tidy up