bug fixes and more cleaning