Ported code for clock v5