All methods must be inside of a class.
The code needs to define a class before defining methods. Move the method inside of the class.