Refactored and Simplified the Train movement logic