Optimize a bit. Ticket #2909 and Ticket #2822