Fixed cast
Thanks to Nukotan for his patch
https://gist.github.com/Nukotan/b3576c77a59524f43939