added segment structure, and adding methods. Added more comments