Basic refactoring on some common code