rewrite to simplify code and make it easier to add new object types