added in functional tests and found some bugs to fix