refactoring of some methods to make them generic.