Bug fixes and test rewiring