More refactoring and little fixes
forgotten file :)