Cleaned and reorganized code.