cleaned up borrowed code