refactoring code. Add adaptive_growing funciton.