Moved main method and tests to separate functions