refactoring blocking UI code