Fundamental rewrite of MAXfocus scripts