Refactored methods to make them easier to understand