moved some logic to helper methods