move some code out of main.asm