MongoDB: Avoid endless loop when indent is set to 1, cleanup code