Refactor some js stuff into namespaces