added printOutput() function, re-organized functions