Preparing for regularization support; fixed memory leaks