moved trail code into separate js file