current version of Dean's code from g-docs