Updated headers and defines and removed spaces

Removed almost 1k in spurious spaces. Put in header and cleaned up.
Created new defines and used them to simplify and document code.