changed some things to make code  re-usable