updated sql functionality