Refactor and split up search