removal of duplicated code and code tidying