updated codes: more user-friendly