added optional limit parameter to database query
added limits to some queries