AJAX for new / edit, cleaned up code in other places