Refactor the pieces page code such that the handling of various table states is abstracted away.