TOOK HOURS to figure this out