You can use SPSecurity.RunWithElevatedPrivileges:
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(web.Site.ID))
{
// implementation details omitted
}
});
That way you don't need to add and remove permissions and can execute code in the context of the application pool account.