improved the log function