Refractored version.