add heartbeat function, and some bug fixed