Cleaned up and commented code.