Refactor the code to make clearer, reduce atom usage.