Cleaned up code and removed magic number