Refactoring, no more repeated code blocks