modified edit function: changed conditionals, added exceptions