Cleaning up some code and adding edit functionality