re-written/structured matlab scripts