Code cleanup, offset bug fix, better docstring.