initial working version with help from roman