fixed a bug and refactored code out to separate namespaces to keep things separate