origin finding (quite complicated)