Added output logic, removed test print statements.