Add mutation function
Clean up code and add comments