checking for invalid pointer index