final tested code