modularize the code