Cleaned up some code and added counters for debugging
Final commit for the day