Refactor viewmodel into constructor function

Change-Id: I1836db724a146521cc0b3a94696498eaa4f0fffb