updated logic statements to fix a bug

still has an issue with variables needed to be declared first.