how do trains work