Original C Version