added method to count spaces in both directions