Adds functional tests and fixes bugs these highlighted