fixed namespaces and reorganized code ab it