catching errors when building queries, avoids crashes