some bug fixes and mprovements