Some Fixes

and optimizations