Some optimization, fixed copyright.
Fixed copyright for borrowed code :p