bug fixes and test restructure