fix header, query parsing and code formatting