fixing sql bug