[Refactoring] unitfactory and state

adjusted to IFactory interface
fixed state not to evoke runtime error