Refactored interaction code