The IVLen var seems be a net loss in clarity. Drop it. Also add comments and normalize error messages.