Don't construct targetItem or player unless they are needed. For example, if itemEx.itemid is not in the array waterIds, then you just wasted CPU cycles constructing player and targetItem.