Added constants, refactored code