Better implementation of create_iv()