OP's original code