Minor bug fixes and debugging code