Overall feature is implemented. Need to write some optimization and tests.