Your slowest things are going to be lists:append and lists:nth. You should use lists:sublist instead of a filter with lists:nth. And see if there is any way to avoid appending to the end of a list, or walking to a specific position in the other cases. jay