bug fixes and test code additions