Fix some issues with empty tags and cursor starting location, add more unit tests