fixed error and added functional test