refactored out js and routing to remove duplication