Added error check to function levelUp