Fixes database query executing twice bug