Added license headers and some minor code cleanup.