Removed magic numbers and cleaned up the code