Added print statements for clarity.
Merged in better error handling.