Add license headers and improved performance