Fixed factory returning undefined issue