modified to work with Simulink