Refactoring, added comments, added gaussian quadrature rule for numerical integration