reorganize code to be mroe readable given all the deprecation