lots of debugging fixes