Improved code after @hughsie comments.