Added check for index argument which throws IllegalArugmentException. Added a test as well.