working js factory