modularize and clean up