Fixed cursor issues and template insertion