Fix bugs with autogenerated code author: rbkillea