bug fixes and code improvements.