fix logic bug