v 1.0.  taken from appendmadnezz branch