Fix bug in factory