Made it easier to handle errors and use default value Former-commit-id: 1891efa0b0196b2c6602e52631e5e6cefb529137