Remove duplicate code by adding method for column/row validity check