Optimize codes of creating ring