working version, improvements expected