refactory almost finished.