Optimized the program with inlines and references instead of copies.