fixes to several bugs
merge