fixed a few bugs
working on performance optimizations