Refactor: abstract common code, rename variables, use propertyAccess instead of varvar