Fixed bug in factory code.