formating and avoiding code duplication