Refactor and simplfy