refactored to be more object oriented and support more than two scenarios