more platform independent reference implementation