Refactor some bits