lots of fixes. working code