Further implementation and refactor