updated with call to formalineoutput
fixed bugs