Updated following PR review, added integration tests