fixed a bug in the new code