Refactor Extract Function