refactored codes and ui