Refactor initial code