fixed a small logic bug