refactored code to be more efficient with less methods