Templates and fixes bugs