Fully switched to SQL, fixes #314