bug fixes

bug fixes and slight improvements