Updated the code to fix a bug