modified algorithm to choose which is better between horizontal/vertical