Imported from cbk's repo.