Bug fixes and debugging helpers