Cleaning code, adding more constants, correcting some bugs