fix dependencies, fix merge bugs and extend unit tests to cover these cases