random fixes

Better integrate this.
Several fixes all around the code and the template.