Detect when a level is completed, and other fixes