Some minor refactor and pending test fixed