various bug fixes
test and clean up