fix bugs -- working fine now