final code working