Refactor audioformat code