Format code, update .gitignore, fix some possible bugs