Refactor function "learn" (shorten code)