finished merging brooke\'s code