Completely re-factored view model code to make it more understandable and testable.