commented and finalized code