Removed bugs in the code