Prevent error message when there is a datetime object in the query result

Also I did some indentation stuff as wel