tidy up duplicated code and move private methods to end of class for readability