fixed the conversion problem

The brain-dead indexing I was using wasn't working, plus it wasn't very
pythonic.