code in working condition. still misses few free slots.