Fixed factory and added environment class