added some modularity to code