Added some references to where particular code came from/was adapted from.