basically working version, but still problems