Reworking and debugging, major work.
Renaming temporary variables and adding all debug conditionals.