General bug fixes