better if this function is moved to meshlib.