added state to functions