refactored code to minimize extraneous files