Added checks and changed echoing in view.