Adding error reporting and fixing index