fixed error handling, added functionality to pass an array to constructor