First pass at an optimizer