Bugfixes, code cleaning