a bunch of debugging and fixes