Housekeeping

Cleaned code
Removed redundant functions
Moved more functions to debugging.