transferred logic from F# to javascript application