Minor bug fixes and Code Cleanup