Fixed, formatted and documented code.