modified and refactored codes.