added some comments
added some comments and caught some exceptions
removed unused lines
added some exception handling