Code cleanup
Check that an index exists before checking it's value