Refactor

Common method and remove dead code