minor reference and error handling fixes