Cleaned up some ugly code in the edit method.