RICPLT-2911 Add missing error branches and do some cleanup.