Sync up with latest prototype

Requires heavy cleanup.