// with credit from scott bowman