clean up and refactor opaleye code