fixed a bug in the code