changed log() to write.log() to avoid conflict with logarithms