refactor to allow easier reuse as a Ruby API