This method feels too long and confusing to me now, I think this logic needs to be simplified or broken out.