attempting to modularize the functions--this should have been written as an object