moved logic to its own method