fixed a bug
extended the code