Fixed bugs, reworked implemented factories to be more flexible.