lots of bug fixes and polishing