code cleanup

removed duplicate code
add more doc headers