fixed bug and some clean up