Added log method to log to file. Various bug fixes.