Extract pushOnStack and popFromStack methods