minor bug fix/error checking