refactored query for tasks.php, perhaps things will be a bit faster