various bug fixes and testing