reworked as a factory, cleaned up