Cleanup 

Replaces #616, includes #626 and #627.