Code cleanup, split apart large function
Code cleanup, use a common struct for line parameters