added check for nil in query for params call