a long list of fixes 

See the commits below