removed usage of &$index
added extra test