merged changes from Bruces GitHub (credit: Bruce2728)