Code clean up and add copyright