added departments, some refactoring