fix quality flaws and refactorings