Fixed Issue #4 with a optimization algorithm