added factories, refactored.