Refactored namespaces and split a few things up. A couple of functions were renamed too.