Refactored code for less repeating statements, got edit/update function working