Trying to modularize code