Add more robust method to determine doc types