Cleans up and adds handling for zero documents