moving method into a function