Renamed some key variables and added preprocessor macro for keys.

Also noticed a few errors and fixed them (lines 1109, 1350)