This was the original implementation, but I've fixed it up :)