fixed problem with array index, added try catch blocks for hooks