improved algorighm