Refactored to have an immutable vm that's passed around to all the functions