implement user variable management, also a bit of refactoring