stolen a useful function from arkham