working version, documented