First working f# implementation