adding error check to prevent null pointer (there is still a bug in the UI)