Refactor to make code more simple