Code from http://wootstudio.ca/towergamekit