Fixes by mbarkhau and andyhtmln. Thanks!