It actually seems to friggin work. Fixed some more syntax problems and an off-by-one error.