Address embray comments, fix UnboundLocalError