major refactoring, added switch factories