small bugfixes and code cleanup