Adding documentation and cleaning up debug output