going to merge for now anyway but we should try and move some of this logic out a bit so these functions don't get super bloated