Added copyright notice and cleaned up the code.