Added functional test, fixed problems