Fixed erronous event numbers for updating inputs/outputs. Cleaned-up code to avoid these errors in the future.