More database awareness/bug fixing