Rest of functions copied from old MLS.R