Smart algorithm implemented, not working,