added ternary operator on saving csv file