Refactor oracle code