added debug, and some try catch, as well as documentation