rearranged code and added everything to an object