calculating the best case and fixed a bug