added small optim, and fixed level ending