Reorganized code and commented everything except search.