added comments, fixed lose condition