Adapted to run on R 3.0.1