this is really complicated to figure out.