general code cleanup und refactoring