Fixed a bug. Added inline documentation.