Using Apache Math3 now
some refactoring