Added debug option
Add error handling
Rev to v1.0