Added end-to-end-test, minor refactoring