Refactored code to make for better self documentation