Solved the problem and added test to cover it.