refactored view code into viewmodel like pattern