Added support for onLast and other improvements