Added test for upgrading train, fixed a few upgrade related bugs