Reorder code to avoid unnecessary forward declarations