fixed to work with R < 3