Solves two SQL bugs