Added port parameter to generate() method, with tests