bug fixes and additional tests