Added integration tests & refactoring