adding an helper function for lpop and rpop