Removed all code repetitions, secondary functions now call main
function.