Multiple code fixes

Fixes #222, #225, #226, #238, #239, #240, #242
This is not the correct calculation of `firstInLine` (it doesn't handle characters at column 0).