Fix bug where SQL statement is run even though there is no class coming up.