added optional output file printing
fixed missing fi error
added option file output