Fix some errors, change template a bit