added check by numRows()
changed to public api where it was possible
reformat code to comply with the coding guidelines