refactored to separate constants, structs, and function prototypes; also, this is a pretty good version of the demo as it is stable, generally around the right angle