Generalized to allow multiple hidden layers