adding initial code from Caphalor