fixed the issue with the edit / add buttons not working as intended.
cleaned up some code