Refactor and add solution extraction functions