Cleaned up logic in the chain construction.