Code improved removed duplicate code

adding validateComponent method
refactoring removeSegment method