Refactor, var cleanup, comment tidy