Extracted code from internal project and got tests to pass