Remove unused code
Extract more common functionality in refactored code