fix couple bugs in edit category, refactor code