Rewrite messy LSN-code