Fixed code, thanks to @stof