refactor the prolem solution