Added conditions to avoid reading from empty DB

Added extra checks to make sure an exception isn't thrown from trying to access a field from a null object. Also added a 'databaseReady' listener for when to load existing data, but the event has never fired in testing. The queries from that event's callback were also added to a callback that runs when the dom is ready. This isn't ideal, but it hasn't caused any bugs in testing so far.