Thanks for the comments. I haven't done a lot of things in javascript, so I'm not entirely familiar with how to optimize it properly.