Added more documentation and clean up duplicate code