Refactoring some functions towards a common library.