Added more javadoc and made the implementation little more simpler.