updated db queries and fixed small errors