ported, commented code from matthew burdick's verion to generate a star