some bug fixes and added test