new (more) modularized implementation