Upgraded to-map() with checks and support for zero-based indexing