integration stuff, courtesy of king q-bert