Moved extract capabilities code into seperate function