compartmentalized database reading into readDatabase() and added error checking.