added selectEmptySlot function