modularize and refactor units