Refactored code and removed magic numbers