revision to handle multiple hidden layers