refactored codes and UI