Now connects to database only once rather than every time it needs to access it.