Clean up code a bit, define constants