Logs everything in to log file, some refactorings