Fixed various bugs so more tests are green now