finalized bin search tree impl and fixed memory leaks