Refactoring

Remove some duplicate code