Refactored backpropagation algorithm to Layer class