Fixes several bugs and improves extension template