Fixed #516 , added test case
Ported 2 failing functionaltests