Still not working quite properly, but I have ideas about how to fix it