simulation function written