merge bugs fixes; refactor