Refactor and web fix for UI