updated to promote readability
fixed issue with errors when the result set is empty