Code review changes - move code to test, minor refactor