first well working copy

now works in a reasonable speed