Refactored ui script