Linked up chunk checking function where needed.
Corrected SQL query.