refactored codes