ported through section 1.4 of ublaze tut