code rework, less globals