Probably could be more efficient but it works.