This feature is build in V4.1. Consider upgrading, because building your own is a hassle.
Regards,
Ronald