Added comments, removed debug printing and removed uneeded function.