some bug fixes and tests