working need to refactor to make more efficient