changed to take stream rather than filename