needs refactor but works