reformat
add lock to collection cache
update template
[refactoring] copy code blocks into methods to make code simple read