manually merged in changes from timothyarmes fork