bug fixes and updated tests