Improved code
Bugfixes