restructuring the code, creating a few methods.
cleanup