Messy but working: server gets raw from database when required

Also, many cleanups and reorganizing.