Fixed bug in trainNetwork()