added the leveling function