Bug Fixing and code improvement