refactored init logic and init UI logic