merged code from jgrenon