Adding tim's code. basis for the rest of the short answer stuff.