refactor with api.rb