some refactorings / bugfixes