refactoring in progress, learned function simulation working