UBI: some code re-structuring