Using snake_case, fixed using tmp files, changed errorhandling