fix several stuff, add template based layout control.