refactoring and added the beginning of simplex discretization
added protection for ZeroDivisionError
fixed merge