restructuring and trying to reduce memory footprint