added updated modularizing code