modifies immediatley invoked function to query db