Cleaning up for migration to MATLAB