cleaned up some code/bugs and fixed logic in edit