section A

integrated everything in one function