Refactor further into more methods

Based on maxme’s suggestions, refactored the code into many more methods