initial working version. still needs much work.