Added functional test and more unit tests