Bug fixes to .img output: wasn't using position parameter to correctly construct filename.