optimize two functions