Added an optional output parameter
Removed some print statements