Fixed some bugs and added license headers