addressed corner case
modularized