Modularize code better