Add documentation to function "likelihood"

Also made a few changes to the code.