code working fine with a few bugs