added base code for detecting the end of a row
Detecting end of the row reiably should work now, it compiles but needs to be tested, its midnight and I'm too tired to test it at the moment