Refactored and removed the need for 2 arrays (d_out and d_in) to be passed in by just overwiting the input array.
Other minor changes.