cleaned up factory and overall code