moved code from example to here