Maybe you can move both 'onContentChanged' out side the if statement and just set the 'lastItem' for different cases.