Adding functional testing, fixing some issues discovered by testing.