Remove code duplication

Remove code duplication