Refactored to use one function and "vm" instead of "this"