devide huge main function into some sub routines

and encapsule some valuables into defun.