Only load database if it is required. This way we can use other queue backends and save initialising the database.
Move count up to prevent undeclared variable.