Fixed a bug in the code and updated output