Change hardcoded indexing to dynamic one.

Signed-off-by: Dhananjay Nakrani <dhananjaynakrani@gmail.com>