added commenting and main functions