refactored and added formatting