Fixed some issues with wandering algorithm