Output sql that works in PostgreSQL. Run everything in a single thread. Reduced number of classes so that logic is easier to follow.