modified for pipleline,
however, this module uses too many reg...