Small performance fixes

According to the discussion in #262
Merge pull request #271 from bpierre/perf-fixes

Performance fixes