template refactor, fixed some focus bugs