Improve function code + change filename extension