a lot of bug fixes and some design improvements