Fixing return value for factory function