Added some error handling, debug printing