Added copyright. Fixed a couple of bugs.