Fix file namespace and refactor code