Add main method to ease testing
Try to clean up the global variables, agent still doesn't work