Added more error control
Removed discard messages at start of function