I think I have a bug in my Javascript code, and it's slowly driving me insane...