added copyright header and clean up code