various fixes from insight

see https://insight.sensiolabs.com/projects/84018111-5762-4f37-932a-1777acaa1d8f/analyses/12