many bug fixes and changes