added debug output console, added comments
documented many functions, write debug output to console