fix logic bug in old code