Why is all this code necessary?