small bugfixes and refractoring