Added a functional test and did some minor cleanup