Reafactor and cleanup