expanded on the main function, more user-friendly now