Added scheduler and refactored heartbeat