Completely refactored code to follow the MVVM architectural design pattern.