working initially, a few bugs remaining