Syntax/bug fixes, added documentation (comments, updated docstrings)