added comments, removed debug outputs