clean template and some fixes