refactor into multiple files, non linear optimization