refactor MOS6502