time complexity has been improved