Refactors dimension function.