refactored ui handler a bit