Add License information and fix some code