added functions to update string and cleaned up code