some bug fixes and clean up.