Add loading spinner and fix layout template bugs