Fixed file-logging bug and cleaned up logging code