attempt to modularize code