refactored and added further var support