Manually merged  PR 137
Fixed compile errors and tests