Cleaned up code. Removed magic numbers and made it more readable.