Database scanning bug