Rearranging logic in getting data