Major code cleanup. Removed legacy codes. Rewrote test code to adjust.