WIP: fixing lots of bugs