Fix for issues

@libardo  could you kindly code review when you have a moment? n2cms/n2cms#542

Please view diff with ?w=1 for best results
https://github.com/n2cms/n2cms/pull/546/files?w=1

Thanks,
Ben