BUG: Fixed bugs pointed out by @pv