Refactor of previous code