updated sql and controllers