merged davids idea but kept aware of variables