Major refactor and added support for varregions (first cut)