GP: Moved out function definition from main function