Fixed code according to @zaggino comments