moving code to method