Make output file name have correct expansion and fix MAX_LEVEL.