Fixed bug in the code