refactored code for easier editing