Improved simulator (tested)