fixed some silly bugs
writed some tests and it runs fast if len(w) <= 10000, after this, too slow..