Fixing Ryan's code