Format code and small improvements