Fixed a small query error and used HEREDOCs to make them more readable