refactor apu code