Changed name and scope of functions to simplify all the things