rewrote demo in pure java