Cleaned up code by removing debugging output, obsolete TODOs and comments and redundant functions.