complete code working fine