Commented and clean up the code