Cleanup coding style, added docstrings, fixed issue with tab-indentation.