Sorted out some database checking