heartbeat fix, db closure added