tested and updated for rev 2