Improve plan algorithm