working - now changing sql queries