changed sql to stop screwing us over