Major refacoring (complete)