Smarter algorithm added