Extract magic numbers to constants.py, clean up minor details
fixed stuff