more bugs to squash, slight refactor