Added two row pattern test for two row input
Refactoring by encapsulating code blocks into methods
More refactoring and cleaning up