Added a bunch of commenting and further extracted some functions. Added __str__ method for commandline usage.