Refractor code, move the code from NeverwinterDP