further reduce duplicate code, make assertion work