extracted wave functionality to new class Wave; added multiple entrance
and multiple exit logic;