general refactorings and bug fixes