rewriting to better organize code