added input value checking, added other boundary conditions
fixed delete