Made some optimizations and fixes

Broke the code though