Refactored a lot of code into constants and more reliable, robust code