move functions inside module

Some functions were defined outside the module, while the types they operate on were defined inside the module. As a result, Distributions.jl fails to compile 

```jlcon
julia> using Distributions
ERROR: UnivariateDistribution not defined
 in include_from_node1 at loading.jl:92
 in reload_path at loading.jl:112
 in require at loading.jl:48
at /Users/aviks/.julia/Distributions/src/Distributions.jl:1876
```