added SQL queries and some jquery functions