Moved task logic to method