Updated database script (still takes too long to run)