added comments, fixed level counting