Various fixes and optimizations

Fixed issue #5
Removed mess