Refactor to support a variable number of hidden layers