Fix some byte-compile issue

- declare local variable
- use with-current-buffer instead of save-excursion + set-buffer
- remove unused variable
- use goto-char + forward-line instead of goto-line