Refactoring to get the implementation more generic.