added some comments, removed unused file output
made declarations more concise, added comments
removed old unused variable