updated code to be compatible with R 3.0