Refactor: Shift logic into ragtime.sql