minor bug fixes and code cleaning..