code refactory for #32