Fixed code for version 3