New code from Fred containing hp_sleep function etc.