modularize code further