Move some codes out of template
Merge pull request #1551 from xillibit/k30_bugs10

Move some codes out of template