Cleaned up code, removed magic numbers.