Code has been rewritten and adds documentation